<!-- 用户编辑弹窗 -->
<template>
  <ele-modal width="680px"
             :visible="visible"
             :append-to-body="true"
             :close-on-click-modal="true"
             custom-class="ele-dialog-form"
             title="修改技师名称"
             @update:visible="updateVisible">
    <el-form ref="form"
             :model="form"
             label-width="82px">
      <el-input clearable
                v-model="form.technicianName"
                placeholder="请输入技师名称" />
    </el-form>
    <template v-slot:footer>
      <el-button @click="updateVisible(false)">取消</el-button>
      <el-button type="primary"
                 :loading="loading"
                 @click="save">
        修改
      </el-button>
    </template>
  </ele-modal>
</template>
  <script>
import {
  technicianList,
  getByTechnicianComments,
  technicianDetail,
  technicianDelete,
  technicianUpdate
} from '@/api/technicianManagement/technicianList';
export default {
  components: {},
  props: {
    // 弹窗是否打开
    visible: Boolean,
    // 修改回显的数据
    data: Object,
    id: String,
    status: String
  },
  data () {
    const defaultForm = {
      technicianName: ''

    };
    return {
      defaultForm,
      // 表单数据
      form: { ...defaultForm },
      // 表单验证规则
      rules: {},
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false
    };
  },
  computed: {
    // 是否开启响应式布局
    styleResponsive () {
      return this.$store.state.theme.styleResponsive;
    }
  },
  methods: {
    /* 保存编辑 */
    save () {
      this.$refs.form.validate((valid) => {
        if (!valid) {
          return false;
        }
        this.loading = true;
        const data = {
          ...this.form
        };
        console.log('isUpdate', this.isUpdate);

        technicianUpdate(data)
          .then((msg) => {
            this.loading = false;
            this.$message.success(msg);
            this.updateVisible(false);
            this.$router.go(0);

          })
          .catch((e) => {
            this.loading = false;
            this.$message.error(e.message);
          });
      });
    },
    /* 更新visible */
    updateVisible (value) {
      this.$emit('update:visible', value);
    }
  },
  watch: {
    visible (visible) {
      if (visible) {
        if (this.id) {
          this.form.id = this.id;
          this.form.status = this.status;
        }
      } else {
        this.$refs.form.clearValidate();
        this.form = { ...this.defaultForm };
      }
    }
  }
};
  </script>
  <style lang="less" scoped>
/deep/.ele-dialog-form .el-dialog__body {
  padding-bottom: -1px;
  display: flex;
  justify-content: center;
}
</style>
  